import 'package:flutter/material.dart';

///文本样式  https://api.flutter-io.cn/flutter/painting/TextStyle-class.html
const testStyle = TextStyle(

    /// 字体颜色
    color: Colors.red,

    /// 文本装饰器(删除线)
    decoration: TextDecoration.lineThrough,

    /// 字体大小
    fontSize: 22.0,

    /// 字体样式 是否斜体
    fontStyle: FontStyle.italic,

    ///字体粗细
    fontWeight: FontWeight.bold,

    /// 文字间距
    letterSpacing: 2.0);

final testStyle01 = testStyle.copyWith(color: Colors.amber);

///
///  学习 text 文本控件相关  https://api.flutter-io.cn/flutter/widgets/Text-class.html
///
///  RichText https://api.flutter-io.cn/flutter/widgets/RichText-class.html
///
///
class TextPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: AppBar(
          title: Text("文本组件使用"),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SizedBox(
              width: double.infinity,
              child: Container(
                color: Colors.yellow,
                child: Text(
                  "这是测试字体相关",
                  style: TextStyle(
                      fontSize: 18,
                      color: Colors.black,
                      fontWeight: FontWeight.bold),
                  textAlign: TextAlign.justify,
                ),
              ),
            ),

            Text(
              "这是测试字体相关基本使用12222222222222222222222222222222223",
              style: testStyle01,
              textAlign: TextAlign.center,
              overflow: TextOverflow.ellipsis,
            ),
            // 构建不同样式 text(类似span)
            Text.rich(TextSpan(
                text: "标题1",
                style: TextStyle(color: Colors.red, fontSize: 22.0),
                children: [
                  TextSpan(
                    text: "标题2",
                    style: TextStyle(color: Colors.yellow, fontSize: 10.0),
                  ),
                  TextSpan(
                    text: "标题3",
                    style: TextStyle(color: Colors.blue, fontSize: 16.0),
                  )
                ])),
            RichText(
                text: TextSpan(
                    text: "标题1",
                    style: TextStyle(color: Colors.red, fontSize: 22.0),
                    children: [
                  TextSpan(
                    text: "标题2",
                    style: TextStyle(color: Colors.yellow, fontSize: 10.0),
                  ),
                  TextSpan(
                    text: "标题3",
                    style: TextStyle(color: Colors.blue, fontSize: 16.0),
                  )
                ])),
            RichText(text:
            const  TextSpan(text: "Hello",style: TextStyle(color: Colors.black,fontSize: 12)),
              selectionRegistrar: SelectionContainer.maybeOf(context),
              selectionColor: Colors.green,
            ),
            Text(
              "自定义字体",
              style: TextStyle(fontFamily: "myfont", fontSize: 36.0),
            ),
          ],
        ));
  }
}
